package com.design.graduation.asdemo.controller;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.design.graduation.asdemo.R;
import com.design.graduation.asdemo.base.ActionBarActivity;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

/**
 * Created by lijinyuan on 16/2/20.
 */

@EActivity(R.layout.activity_personal)
public class PersonalActivity extends ActionBarActivity {
    Animation animation;
    private int[] img = new int[]{
            R.drawable.appintro1,
            R.drawable.appintro2,
            R.drawable.appintro3,
            R.drawable.appintro4,
    };
    private int imgResID = 0;

    @ViewById(R.id.personal_bg)
    ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @AfterViews
    public void initView() {

        handler = new Handler();
        setImgAnimation();
        setToolBar();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        MenuItem text = menu.findItem(R.id.action_text);
        MenuItem img = menu.findItem(R.id.action_img);
        text.setVisible(false);
        img.setVisible(false);
        return true;
    }

    private void setToolBar() {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle("个人中心");
        setSupportActionBar(toolbar);

    }

    private void setImgAnimation() {
        handler.post(animationHandler);
    }

    Handler handler = new Handler();
    Runnable animationHandler = new Runnable() {
        @Override
        public void run() {
            imageView.setImageResource(img[imgResID++ % img.length]);
            handler.postDelayed(animationHandler, 5000);
            animation = AnimationUtils.loadAnimation(PersonalActivity.this, R.anim.troll);
//            Animation animation = new ScaleAnimation(
// 0.9f, 1.0f, 0.9f, 1.0f,0.5f,0.5f);
//            animation.setDuration(5000);
//            animation.setRepeatCount(-1);
//            imageView.startAnimation(animation);
            imageView.startAnimation(animation);
        }
    };


    public void toWrite(View view) {
        startActivity(new Intent(PersonalActivity.this, WriteDetailsActivity.class));
    }

    public void toSolicit(View view) {
        startActivity(new Intent(PersonalActivity.this, SolicitingActivity_.class));
    }

}
